/**
 * @param {string} s
 * @return {number}
 */
var longestPalindromeSubseq = function(s) {
    let len = s.length,
        dp = new Array(len + 1).fill(0).map(() => new Array(len + 1).fill(0));

    for (let i = len; i > 0; i--) {
        for (let j = i; j <= len; j++) {
            if (s[i - 1] === s[j - 1]) {
                if(j===i){
                    dp[i][j] = 1
                }else {
                    dp[i][j] = dp[i+1][j-1] + 2
                }
            }else{
                dp[i][j] = Math.max(dp[i+1][j-1],dp[i+1][j],dp[i][j-1])
            }
        }
    }

    return dp[1][len]
};